package com.cy.dda.web.front.goodsdiligencing;

import com.cy.dda.comm.utils.CommonUtils;
import com.cy.dda.model.Result;
import com.cy.dda.model.ao.goodsdiligencing.VerifyTruthReportSaveAO;
import com.cy.dda.model.enums.goodsdiligencing.GoodsDiligencingAttachmentType;
import com.cy.dda.model.vo.goodsdiligencing.GoodsDiligencingReportAttachmentVO;
import com.cy.dda.model.vo.goodsdiligencing.VerifyTruthReportDetailVO;
import com.cy.dda.service.goodsdiligencing.VerifyTruthReportService;
import com.cy.dda.web.BaseController;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.BindingResult;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * @Description 前台-家具尽调  验真报告 controller
 * @Author tanyilin
 * @Date 2019/8/27 17:18
 */
@RestController
@RequestMapping("/user/goods/diligencing/verifyTruth/report")
@Api(tags = "前台-家具尽调 verifyTruth验真报告 controller")
public class VerifyTruthReportController extends BaseController {

    @Autowired
    private VerifyTruthReportService verifyTruthReportService;

    @ApiOperation("验真报告详情回显")
    @GetMapping("/get/detail")
    public Result<VerifyTruthReportDetailVO> getDetail(@RequestParam(value = "goodsDiligencingId") Long goodsDiligencingId) {

        VerifyTruthReportDetailVO detailVO = verifyTruthReportService.getVerifyTruthReportDetail(goodsDiligencingId);
        return ok("获取验真报告数据成功".concat(CommonUtils.isEmpty(detailVO) ? "，但无数据" : ""), detailVO);
    }

    @ApiOperation("获取报告照片列表")
    @GetMapping("/get/attachment/list")
    public Result<List<GoodsDiligencingReportAttachmentVO>> getAttachmentList(@RequestParam(value = "verifyTruthReportId") Long verifyTruthReportId,
                                                                              @RequestParam(value = "type") GoodsDiligencingAttachmentType type) {

        List<GoodsDiligencingReportAttachmentVO> list = verifyTruthReportService.getVerifyTruthReportAttachmentList(verifyTruthReportId, type);
        return ok("获取照片数据成功".concat(CommonUtils.isEmpty(list) ? "，但无数据" : ""), list);
    }

    @ApiOperation("提交保存验真报告图片")
    @PostMapping("/do/save/attachment")
    public Result<Map<String, Object>> doSaveAttachment(@RequestBody @Validated VerifyTruthReportSaveAO saveAO, BindingResult bindingResult) {

        this.checkError(bindingResult);
        Result<Map<String, Object>> result = verifyTruthReportService.saveVerifyTruthReportAttachment(saveAO, this.getUser().getUserId());
        return result;
    }

    @ApiOperation("提交保存验真报告")
    @PostMapping("/do/save")
    public Result<Map<String, Object>> doSave(@RequestBody @Validated VerifyTruthReportSaveAO saveAO, BindingResult bindingResult) {

        this.checkError(bindingResult);
        Result<Map<String, Object>> result = verifyTruthReportService.saveVerifyTruthReport(saveAO, this.getUser().getUserId());
        return result;
    }


}
